/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fanta.framework.persistence;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author alessandro
 */
@Entity
@Table(name = "team")
@NamedQueries({
    @NamedQuery(name = "Team.findAll", query = "SELECT t FROM Team t"),
    @NamedQuery(name = "Team.findById", query = "SELECT t FROM Team t WHERE t.id = :id"),
    @NamedQuery(name = "Team.findByNome", query = "SELECT t FROM Team t WHERE t.teamPK.nome = :nome"),
    @NamedQuery(name = "Team.findByLega", query = "SELECT t FROM Team t WHERE t.teamPK.lega = :lega"),
    @NamedQuery(name = "Team.findByBudget", query = "SELECT t FROM Team t WHERE t.budget = :budget")})
public class Team implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TeamPK teamPK;
    @Basic(optional = false)
    @Column(name = "id")
    private int id;
    @Basic(optional = false)
    @Column(name = "budget")
    private int budget;
    @ManyToMany(mappedBy = "teamCollection")
    private Collection<Giocatore> giocatoreCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idteam")
    private Collection<Formazione> formazioneCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idteam1")
    private Collection<Giornatelega> giornatelegaCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idteam2")
    private Collection<Giornatelega> giornatelegaCollection1;
    @JoinColumn(name = "owner", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Utente owner;
    @JoinColumn(name = "lega", referencedColumnName = "nome", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Lega lega1;

    public Team() {
    }

    public Team(TeamPK teamPK) {
        this.teamPK = teamPK;
    }

    public Team(TeamPK teamPK, int id, int budget) {
        this.teamPK = teamPK;
        this.id = id;
        this.budget = budget;
    }

    public Team(String nome, String lega) {
        this.teamPK = new TeamPK(nome, lega);
    }

    public TeamPK getTeamPK() {
        return teamPK;
    }

    public void setTeamPK(TeamPK teamPK) {
        this.teamPK = teamPK;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getBudget() {
        return budget;
    }

    public void setBudget(int budget) {
        this.budget = budget;
    }

    public Collection<Giocatore> getGiocatoreCollection() {
        return giocatoreCollection;
    }

    public void setGiocatoreCollection(Collection<Giocatore> giocatoreCollection) {
        this.giocatoreCollection = giocatoreCollection;
    }

    public Collection<Formazione> getFormazioneCollection() {
        return formazioneCollection;
    }

    public void setFormazioneCollection(Collection<Formazione> formazioneCollection) {
        this.formazioneCollection = formazioneCollection;
    }

    public Collection<Giornatelega> getGiornatelegaCollection() {
        return giornatelegaCollection;
    }

    public void setGiornatelegaCollection(Collection<Giornatelega> giornatelegaCollection) {
        this.giornatelegaCollection = giornatelegaCollection;
    }

    public Collection<Giornatelega> getGiornatelegaCollection1() {
        return giornatelegaCollection1;
    }

    public void setGiornatelegaCollection1(Collection<Giornatelega> giornatelegaCollection1) {
        this.giornatelegaCollection1 = giornatelegaCollection1;
    }

    public Utente getOwner() {
        return owner;
    }

    public void setOwner(Utente owner) {
        this.owner = owner;
    }

    public Lega getLega1() {
        return lega1;
    }

    public void setLega1(Lega lega1) {
        this.lega1 = lega1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (teamPK != null ? teamPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Team)) {
            return false;
        }
        Team other = (Team) object;
        if ((this.teamPK == null && other.teamPK != null) || (this.teamPK != null && !this.teamPK.equals(other.teamPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fanta.framework.persistence.Team[teamPK=" + teamPK + "]";
    }

}
